package valleyOfDemon;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 获取请求对象的路径信息和一些其他信息
 */
@WebServlet("/ServletDemo01")
public class ServletDemo01 extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("URL:" + req.getRequestURL());
        System.out.println("URI:" + req.getRequestURI());
        System.out.println("虚拟目录:" + req.getContextPath());
        System.out.println("getServletPath:" + req.getServletPath());
        System.out.println("查询语句:" + req.getQueryString());
        System.out.println("本机地址:" + req.getLocalAddr());
        System.out.println("本机名字:" + req.getLocalName());
        System.out.println("端口号:" + req.getLocalPort());
        System.out.println("ServerName:" + req.getServerName());
        System.out.println("getPathInfo:" + req.getPathInfo());
        System.out.println("etProtocol:" + req.getProtocol());
        System.out.println("CharacterEncoding:" + req.getCharacterEncoding());
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
